<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<canvas id="canvas" class="output" width="300" height="350">
    <button id="button1"></button>
    <button id="button2"></button>
</canvas>
<script>
var canvas = document.getElementById("canvas").getContext("2d");

document.getElementById("button1").addEventListener('focus', function() {
    canvas.beginPath();
    canvas.rect(50, 50, 200, 100);
    canvas.fillStyle = "#ccf";
    canvas.fill();
    canvas.drawFocusIfNeeded(document.getElementById("button1"));

    canvas.beginPath();
    canvas.rect(50, 200, 200, 100);
    canvas.fillStyle = "#cfc";
    canvas.fill();
    canvas.drawFocusIfNeeded(document.getElementById("button2"));
});

test(function(t) {

    document.getElementById("button1").focus();
    
    // The top rect's focus ring is tied to button1, which is focused.
    // It should have an outline in some color other than the background color.
    var imageData = canvas.getImageData(49, 50, 1, 1);
    var data = imageData.data;
    assert_true(data[0] != 0 || data[1] != 0 || data[2] != 0);
    
    // The bottom rect"s focus ring is tied to button2, which is not focused.
    imageData = canvas.getImageData(49, 200, 1, 1);
    data = imageData.data;
    assert_true(data[0] == 0 && data[1] == 0 && data[2] == 0);
    
}, 'Test that drawFocusIfNeeded does not crash on event.');
</script>
</body>
